package xianchengpool;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


/**
 * @功能
 * @创建时间 2019/12/27
 */
public class T14_ParallelStreamAPI {

    public static void main(String[] args) {
        Random r = new Random();
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i<10000;i++)
            nums.add(1000000+r.nextInt(1000000));
        System.out.println(nums);
        long start = System.currentTimeMillis();
        nums.forEach(v->isPrime(v));
        long end = System.currentTimeMillis();
        System.out.println(end-start);
        //使用parallel stream api
        start = System.currentTimeMillis();
        nums.parallelStream().forEach(T14_ParallelStreamAPI::isPrime);
        end = System.currentTimeMillis();
        System.out.println(end-start);

    }
    static boolean isPrime(int num){
        for(int i=2;i<=num/2;i++){
            if(num%i == 0)
                return false;
        }
        return true;
    }
}
